//
//  ExploreCollectionViewCell.m
//  EDPS
//
//  Created by 张维扬 on 15/11/26.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "ExploreCollectionViewCell.h"

#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface ExploreCollectionViewCell ()
@property (nonatomic, strong) UIImageView *index_cover;
@property (nonatomic, strong) UILabel *index_title;
@property (nonatomic ,strong) UILabel *spot_region; // 地点
@property (nonatomic, strong) UIView *textBg;//文字背景颜色;
@property (nonatomic, strong) UIImageView *avatar_m;// 用户头像
@property (nonatomic, strong) UILabel *name; // 用户名
@end

@implementation ExploreCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置每个item的圆角
        self.contentView.layer.cornerRadius = 5;
        self.contentView.clipsToBounds = YES;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.index_cover = [[UIImageView alloc] init];
//        self.index_cover.clipsToBounds = YES;
        self.index_cover.contentMode = UIViewContentModeScaleToFill;
        [self.contentView addSubview:self.index_cover];
        
        self.textBg = [[UIView alloc] init];
        self.textBg.backgroundColor = [UIColor whiteColor];
        [self.index_cover addSubview:self.textBg];
        
        self.index_title = [[UILabel alloc] init];
        self.index_title.numberOfLines = 0;
//        self.index_title.backgroundColor = [UIColor redColor];
        [self.index_title setFont:[UIFont systemFontOfSize:14]];
        [self.textBg addSubview:self.index_title];
        
        self.spot_region = [[UILabel alloc] init];
        [self.index_cover addSubview:self.spot_region];
        self.spot_region.textColor = [UIColor whiteColor];
        [self.spot_region setFont:[UIFont systemFontOfSize:12]];
        
        self.avatar_m = [[UIImageView alloc] init];
        [self.textBg addSubview:self.avatar_m];
        self.avatar_m.layer.cornerRadius = 10;
        self.avatar_m.clipsToBounds = YES;
        
        self.name = [[UILabel alloc] init];
        [self.textBg addSubview:self.name];
        [self.name setFont:[UIFont systemFontOfSize:12]];
        self.name.textColor =[UIColor grayColor];
        
    }
    return self;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [self.textBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(0);
        make.right.mas_equalTo(self.contentView.mas_right).offset(0);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(0);
        make.height.mas_equalTo(ScreenWidth * 0.2);
    }];
    
    [self.index_cover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height));
    }];
    
    [self.index_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.textBg.mas_top).offset(5);
        make.left.mas_equalTo(self.textBg.mas_left).offset(5);
        make.right.mas_equalTo(self.textBg.mas_right).offset(-5);
        make.height.mas_equalTo(ScreenWidth * 0.1);
    }];
    
    [self.spot_region mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(5);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-5);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        
    }];
    // 用户头像
    [self.avatar_m mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.contentView.mas_left).offset(5);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-5);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        
    }];
    // 用户名
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.avatar_m.mas_centerY);
        make.left.mas_equalTo(self.contentView.mas_left).offset(30);
        make.size.mas_equalTo(CGSizeMake(100, 20));
        
    }];
}
- (void)setModel:(ExploreModel *)model
{
    if (_model != model) {
        _model = model;
    }
    [self.index_cover sd_setImageWithURL:[NSURL URLWithString:model.index_cover] placeholderImage:[UIImage imageNamed:@"hold"]];
    self.index_title.text = model.index_title;
}
- (void)setImgName_Model:(imgNameModel *)imgName_Model
{
    if (_imgName_Model != imgName_Model) {
        _imgName_Model = imgName_Model;
    }
    [self.avatar_m sd_setImageWithURL:[NSURL URLWithString:imgName_Model.avatar_m] placeholderImage:[UIImage imageNamed:@"hold"]];
    self.name.text = imgName_Model.name;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
